package org.lboot.idmo.loader;

import lombok.AllArgsConstructor;

import java.security.SecureRandom;

@AllArgsConstructor
public class DefaultPasswordGenerator implements PasswordGenerator{
    // 定义生成密码的字符集
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";

    // 定义生成密码的长度
    private static final int PASSWORD_LENGTH = 8;
    @Override
    public String build() {
        SecureRandom random = new SecureRandom();
        StringBuilder password = new StringBuilder();

        for (int i = 0; i < PASSWORD_LENGTH; i++) {
            int randomIndex = random.nextInt(CHARACTERS.length());
            char randomChar = CHARACTERS.charAt(randomIndex);
            password.append(randomChar);
        }

        return password.toString();
    }
}
